/*

The Effect of Personalized Feedback on Small Enterprises' Finances in Uganda
Antonia Grohmann, Lukas Menkhoff, Helke Seitz

Table 11

*/

set varabbrev off
set more off
cap log close
set mem 500m
clear

/*------[Matrix Start]------*/
set obs 1
forval i= 1(1)7{							
gen Spalte`i' = .
mkmat Spalte`i'
}
mkmat  Spalte1 - Spalte7, matrix(matrixd)   

drop Spalte*
/*------[Matrix End]------*/



use "filepath\Uganda_shortterm.dta", clear




xtset ID_2012_firm wave
	

	
	
local sample=2

gen heterogeneity1=1 if sample_v0`sample'==1

gen heterogeneity2=1 if gender==2 //female
gen heterogeneity3=1 if gender==1 //male
gen heterogeneity4=1 if lcompleted_primary_v2==0 //low skilled
gen heterogeneity5=1 if lcompleted_primary_v2==1 //high skilled
gen heterogeneity6=1 if lfinlit_median==0 //
gen heterogeneity7=1 if lfinlit_median==1 //


 
 


 
local sample=2
#del;
local 
tex_vars3 
rulethumb personalized rulethumb_lsave_time_2017  personalized_lsave_time_2017   lsave_time_2017 
;
#del cr  
  

	
foreach spec in 1 2 3 4 5 6 7   {


  
	if `spec'==1 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }

	if `spec'==2 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }
   
   	if `spec'==3 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }
   
   	if `spec'==4 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }
   
   	if `spec'==5 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }
    
   	if `spec'==6 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }
  
	if `spec'==7 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb personalized_lsave_time_2017   rulethumb_lsave_time_2017 lsave_time_2017 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
	
   #del cr
   }

	   
 
	
	  foreach num of numlist 1 {

      `estcommand'  `lhs' `rhs'  if  sample_v0`sample'==1 & sample_sav1_v0`sample'==1 & lsave_time_2017>=0 & heterogeneity`spec'==1 , `estoptions'
	   
	   local obs`spec'=e(N) 
	   test _b[personalized_lsave_time_2017]-_b[rulethumb_lsave_time_2017]=0
	   local ttest`spec'=r(p)
	   local r2`spec'=	e(r2)
	   sum `lhs' if control==1
	   local meany`spec'=r(mean)
	   local sdy`spec' =sqrt(r(Var))
	   

	  if ("`spec'"=="1" & "`num'"=="1") {
		 
		 
		   #del;
			est2vec est_v11
				, 
				vars(`tex_vars3') 
				replace name(out`spec'`num');
				
				est2extlbl, addto(est_v11) 
				intex("${TEMP_PATH}/texlabels_e_v01.tex") path(${ESTIMATION_PATH}) 
				replace dropall saving;
			 
						
		  #del cr
		 } /*if*/
		 else {
						est2vec est_v11, addto(est_v11) name(out`spec'`num')

		 } /*else*/
		 #del;
					est2tex8 est_v11, replace preserve 
					path(${ESTIMATION_PATH})
					mark(starb) levels(90 95 99) digits(3) 
					fancy leadzero thousep;
					#del cr
		 
	  
	  
	  
}
}






foreach spec of numlist 1(1)7 {

matrix matrixd[1,`spec']=round(`ttest`spec'',.01)


}

matrix rownames matrixd =  Feedback*PF-Feedback*RT=0(p-value)
matrix list matrixd
outtable using ${DESC_PATH}/est_v11a, mat(matrixd)  replace    f(%9.2f )


